/*


	iic eeprom test


*/

#include <string.h>
#include "2440addr.h"
#include "2440lib.h"
#include "def.h"
#include "IIC.h"
#include "raw_api.h"

extern void Timer0Init(void);

#define IIC_TASK_STK_SIZE     (10*1024)

PORT_STACK iic_task_stack[IIC_TASK_STK_SIZE];

RAW_TASK_OBJ	iic_task_obj;

void iic_int_test(void)
{
	RAW_U16 i,j;
	static RAW_U8 data[256];
	
	IIC_init();
    
	Uart_Printf("Write test data into AT24C02 \n");

	for( i = 0; i < 256; i++ )		Wr24C080( 0xa0, (RAW_U8) i, 88);
        
	for( i = 0; i < 256; i++ )		data[i] = 0;

	Uart_Printf("Read test data from AT24C02\n");
    
	for( i = 0; i < 256; i++ )		Rd24C080(0xa0,(U8)i,&(data[i])); 

        //Line changed 0 ~ f
	for( i = 0; i < 16; i++ )
	{
		for( j = 0; j < 16; j++ )
			Uart_Printf("%2x ",data[i*16+j]);
		
		Uart_Printf("\n");
	}

	IIC_end();
	

}

void iic_poll_test(void)
{
	RAW_U16 i,j;
	static RAW_U8 data[256];

  	_IIC_init();
    
	Uart_Printf("Write test data \n");

	for( i = 0; i < 256; i++)		_Wr24C080( 0xa0, (RAW_U8) i, 66 );

	for( i = 0; i < 256; i++)		data[i] = 0;

	Uart_Printf("Read test data \n");
	
	for( i = 0; i < 256; i++)		_Rd24C080( 0xa0, (RAW_U8) i, &(data[i])); 

	for( i = 0; i < 16; i++)
	{
		for( j = 0; j < 16; j++)
			Uart_Printf("%2x ",data[i*16+j]);
		
		Uart_Printf("\n");
	}
    
	_IIC_end();

}

void task_iic_test(void *arg)
{
	RAW_U8 key;
	
	Timer0Init();
	
	while(1){
		
		Uart_Printf("Press p to choose mode...\n");

		key = Uart_Getch();
		
// 		if( 0x69 == key )

// 			iic_int_test();
	
// 		else 
			if( 0x70 == key )
		
			iic_poll_test();
	
	}
}

void iic_test()
{

	raw_task_create(&iic_task_obj, (RAW_U8  *)"task1", 0,
	                         1, 0,  iic_task_stack, 
	                         IIC_TASK_STK_SIZE , task_iic_test, 1); 

}

